export const getHomeComboList = ()=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/homeCombo`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getSelectComboList = (schoolId = null)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/selectCombo?schoolId=${schoolId}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getSelectComboByStudent = (studentId)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/selectComboByStudent?studentId=${studentId}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getSelectComboListByDate = (date,studentId)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/selectComboByDate?date=${encodeURIComponent(date)}&studentId=${studentId}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getComboInfo = (id)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/combo/${id}`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const createResrve = (data)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/createResrve`,
				method:'post',
				data,
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const getResrve = (params)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/listResrve`,
				method:'post',
				data:params,
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

export const listHistoryResrve = (params)=>{
	 return	new Promise((resolve, reject)=>{
		// 构建查询字符串
		const queryString = params ? Object.keys(params)
			.filter(key => params[key] !== null && params[key] !== undefined)
			.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
			.join('&') : '';
		const url = queryString ? `/admin/wx/student/listHistoryResrve?${queryString}` : `/admin/wx/student/listHistoryResrve`;

		uni.request({
				url,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})

}

// 设置用户选择的学校
export const setSelectedSchool = (schoolId)=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/setSelectedSchool?schoolId=${schoolId}`,
				method:'post',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})
}

// 获取用户当前选择的学校
export const getSelectedSchool = ()=>{
	 return	new Promise((resolve, reject)=>{
		uni.request({
				url:`/admin/wx/student/getSelectedSchool`,
				method:'get',
				success(resp) {
					resolve(resp.data.data)
				},
				fail(e) {
					reject(new Error('请求失败'));
				}
			})
	})
}